<admintpl file="header" />
<style type="text/css">
.pic-list li {
	margin-bottom: 5px;
}
.set_gs {
    width: 515px;
    margin-left: 130px;
}
.p-15 {
    padding: 15px!important;
    border: 1px solid #E0E0E0;
}
.form-control-k {
    background-color: #FFFFFF;
    background-image: none;
    border: 1px solid #e5e6e7;
    border-radius: 1px;
    color: inherit;
    display: block;
    padding: 7px 12px;
    transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
    width: 100%;
    height: 100%;
    font-size: 14px;
}
.o-hidden {
    overflow: hidden!important;
}
.m-t-20 {
    margin-top: 20px!important;
}
.gongshi .left {
    width: 75%;
    float: left;
}
.gongshi .left .show-gs {
    width: 100%;
    min-height: 190px;
    background: #fff;
    border: 1px solid #E0E0E0;
}
.gongshi .right {
    width: 25%;
    float: right;
    text-align: center;
}
/*.p-10 {
    padding: 10px!important;
}*/
.gongshi .right button {
    width: 45px;
    margin-top: 15px;
}
.gongshi .right button.clear {
    width: 94px;
    margin-top: 0;
}
.bgm-red {
    background-color: #f44336!important;
}
.bgm-bluegray {
    background-color: #607d8b!important;
}
</style>
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
                    <li><a href="{:U('Shoufei/gongshiguanli')}">公式管理</a></li>
                    <li class="active"><a href="{:U('Shoufei/gongshiadd')}">新增公式</a></li>
		</ul>
		<!--<form action="{:U('Shoufei/gongshiadd_post')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">-->
                <form class="form-horizontal add">
                        <fieldset>
                            <div class="control-group">
                                <label class="control-label">公式名称：</label>
                                <div class="controls">
                                    <input type="text" style="width:500px;" name="name" id="title" required value=""/>
                                    <span class="form-required">*</span>
                                </div>
                            </div>
                            <div class="control-group ">
                                    <div class="controls set_gs">
                                        <fieldset class="p-15">
                                            <legend style="font-size: 14px;">设置计算公式</legend>
                                            <select name=""  class="form-control-k se_gs">
                                                <option value="">公式中可使用的变量</option>
                                                <option value="$gs1">建筑面积</option>
                                                <option value="$gs2">套内面积</option>
                                                <option value="$gs3">公摊面积</option>
                                                <option value="$gs4">单价</option>
                                                <option value="$gs5">电费起度</option>
                                                <option value="$gs6">电费止度</option>
                                                <option value="$gs7">气费起度</option>
                                                <option value="$gs8">气费止度</option>
                                                <option value="$gs9">水费起度</option>
                                                <option value="$gs10">水费止度</option>
                                                <option value="$gs11">排量</option>
                                            </select>
                                            <div class="gongshi o-hidden m-t-20">
                                                <div class="left"><div class="show-gs p-10"></div></div>
                                                <div class="right ">
                                                    <button type="button" class="btn bgm-red clear">清除</button>
                                                    <button data="+" type="button" class="btn bgm-bluegray yuns">+</button>
                                                    <button data="-" type="button" class="btn bgm-bluegray yuns">－</button>
                                                    <button data="*" type="button" class="btn bgm-bluegray yuns">×</button>
                                                    <button data="/" type="button" class="btn bgm-bluegray yuns">÷</button>
                                                    <button data="(" type="button" class="btn bgm-bluegray yuns">( </button>
                                                    <button data=")" type="button" class="btn bgm-bluegray yuns"> )</button>
                                                </div>
                                            </div>
                                            <input type="hidden" class="form_formula" name="" value="" />
                                            <input type="hidden"  name="wenben" id="wenben" value="" />
                                            <div class="none gongs_list"></div>
                                        </fieldset>
                                    </div>
                            </div>
			</fieldset>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">提交</button>
				<a class="btn" href="{:U('Shoufei/gongshiguanli')}">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript">
            $(function() {
                $('.se_gs').on('change',function(){
                    var va = $(this).val();
                    var ht = $(this).find('option:selected').html();
                    if(va!=''){
                       $('.show-gs').html($('.show-gs').html()+ht+' ');
                       $('.form_formula').val($('.form_formula').val()+va);
                       $('.gongs_list').append('<input type="hidden"  name="list[]" value="'+ht+'" />');
                    }
                });
                $('.yuns').on('click',function(){
                    $('.show-gs').html($('.show-gs').html()+$(this).text().replace(/(^\s*)|(\s*$)/g, "")+' ');
                    $('.form_formula').val($('.form_formula').val()+$(this).attr('data'));
                });
                $('.clear').on('click',function(){
                    $('.se_gs option').attr('selected',false);
                    $('.se_gs option').eq(0).attr('selected',true);
                    $('.show-gs').html('');
                    $('.form_formula').val('');
                });
                $('.add').submit(function(e){
                    e.preventDefault();
//                    var obj = {};
//                    obj.name = document.getElementById("title").value;
//                    obj.wenben = $('.show-gs').html();
//                    eval($('.form_formula').val());
                    $('#wenben').val($('.show-gs').html());
                    try {
                        $.post("{:U('Shoufei/gongshiadd_post')}",$(this).serialize(),function(data){
                            if (data.status) {
                                    setCookie("refersh_time", 1);
                                    //添加成功
                                    Wind.use("artDialog", function() {
                                            art.dialog({
                                                    id : "succeed",
                                                    icon : "succeed",
                                                    fixed : true,
                                                    lock : true,
                                                    background : "#CCCCCC",
                                                    opacity : 0,
                                                    content : data.info,
                                                    button : [ {
                                                            name : '继续添加？',
                                                            callback : function() {
                                                                    reloadPage(window);
                                                                    return true;
                                                            },
                                                            focus : true
                                                    }, {
                                                            name : '返回列表页',
                                                            callback : function() {
                                                                    location = "{:U('Shoufei/gongshiguanli')}";
                                                                    return true;
                                                            }
                                                    } ]
                                            });
                                    });
                            } else {
                                    isalert(data.info);
                            }
                        });
                    }
                    catch(err) {
                        sweetAlert({title:'公式错误',text: '',type: "warning",timer:2000});
                    }
                });
            });
	</script>
</body>
</html>